# Guess words 猜单词游戏
import random

# 创建单词序列元组
WORDS = ("python", "jumble", "easy", "difficult", "answer", "continue", "phone")

# 游戏界面设计
print(
    """
        欢迎参加猜单词游戏
        把字母组合在一起合成一个正确的单词
    """
    "加油呀，少年"
)

iscontinue = "y"
while iscontinue == "y" or iscontinue == "Y":  # 循环游戏
    # 从序列中随机选择一个单词
    word = random.choice(WORDS)
    # 一个用于判断是否组合成功的变量
    correct = word
    # 创建乱序后的单词
    jumble = ""
    while word:  # word不是空串循环
        # 根据word长度，产生word的随机位置
        position = random.randrange(len(word))
        # 将position位置的字母组合到乱序后的单词
        jumble += word[position]
        # 通过切片，将position位置的字母从原单词中删除
        word = word[:position] + word[(position + 1):]
    print("乱序后的单词", jumble)
    guess = input("\n请你猜")
    while guess != correct and guess != "":
        print("对不起，不正确")
        guess = input("继续猜")

    if guess == correct:
        print("真棒，你猜对啦！")
    iscontinue = input("\n是否继续游戏（Y/N）")
